package test.ali;

/**
 * Created by shuoGG on 2018/10/25 0025
 */
public class CalMoney {
    public String cal(String value) {
        String i = value.substring(0, value.indexOf("."));
        String f = value.substring(value.indexOf(".") + 1, value.length());
        if (f.equals("1")) f = "10";
        String upperValue = getUpperValue(f);
        int gap1 = Integer.valueOf(upperValue) - Integer.valueOf(f);
        int gap2 = Math.abs(Integer.valueOf(f) - (Integer.valueOf(upperValue)>>2));
        int gap3 = Integer.valueOf(f);
        int min = getMin(gap1, gap2, gap3);
        if (min == gap1) {
            return i + ".99";
        } else if (min == gap2) {
            return i + ".49";
        } else {
            if (Integer.valueOf(i) == 0) return i + ".49";
            return String.valueOf(Integer.valueOf(i) - 1) + ".99";
        }
    }

    private int getMin(int a, int b, int c) {
        int min = a;
        if (a > b) min = b;
        if (b > c) min = c;
        return min;
    }

    private String getUpperValue(String value) {
        StringBuilder str = new StringBuilder("1");
        for (int j = 0; j < value.length(); j++) {
            str.append("0");
        }
        return str.toString();
    }


    public static void main(String[] args) {
        System.out.println(new CalMoney().cal("0.00"));
    }

}
